from django.db import models

# Create your models here.

class Category(models.Model): #^类别
    CategoryId=models.CharField(primary_key=True,max_length=30,verbose_name="类ID")
    CategoryName=models.CharField(max_length=30,verbose_name="类名")

class Information(models.Model):#^用户信息
    UserId=models.CharField(primary_key=True,max_length=30,verbose_name="用户ID")
    UserName = models.CharField(max_length=30,verbose_name="昵称",null=True,default="无名氏")
    UserAvatarUrl=models.CharField(max_length=30,verbose_name="用户头像",null=True,default="./static/Default-Avatar.png")
    UserPassword = models.CharField(max_length=30,verbose_name="密码")
    MyAutograph=models.CharField(max_length=100,null=True,verbose_name="我的签名")
    MyBlog = models.CharField(max_length=100,null=True,verbose_name="我的博客地址")
    UserEmail = models.EmailField(null=True,verbose_name="我的邮箱",)
    Integral = models.IntegerField(null=True,default=0,verbose_name="积分")
    Isverified = models.BooleanField(null=True,default=False,verbose_name="是否已身份验证")

class Release(models.Model): #^发布
    ArticleId=models.CharField(primary_key=True,max_length=30,verbose_name="文章ID")
    Title = models.CharField(max_length=100,verbose_name="标题")
    Context =models.TextField(verbose_name="文章内容")
    CreateTime = models.DateTimeField(auto_now_add=True,verbose_name="发布时间")
    UpdateTime = models.DateTimeField(auto_now=True,verbose_name="修改时间")
    Viewnum = models.IntegerField(null=True,default=0,verbose_name="观看数")
    Category=models.ForeignKey(to="Category",to_field="CategoryId",name="Category",null=True,on_delete=models.SET_NULL)
    Preview = models.CharField(max_length=160,null=True,verbose_name="列表显示")
    Photo=models.CharField(max_length=160,null=True,verbose_name="图片链接")

class Collection(models.Model): #^收藏
    ArticleId=models.ForeignKey(to="Release",to_field="ArticleId",verbose_name="文章ID(外键)",on_delete=models.CASCADE)
    UserId=models.ForeignKey(to="Information",to_field="UserId",verbose_name="用户ID(外键)",on_delete=models.CASCADE)
    class Meta:
        unique_together=[("ArticleId","UserId"),]#^限制重复

class News(models.Model): #^评论
    ArticleId=models.ForeignKey(to="Release",to_field="ArticleId",verbose_name="文章ID(外键)",on_delete=models.CASCADE)
    UserId=models.CharField(verbose_name="用户ID",max_length=30)
    Text=models.TextField(max_length=200,verbose_name="评论文本")
    ParentLevelId=models.ForeignKey(to="News",to_field="id",null=True,default=None,verbose_name="父级消息ID",on_delete=models.CASCADE)
    CreateTime = models.DateTimeField(auto_now_add=True,verbose_name="评论时间")


class Label(models.Model): #^标签
    ArticleId=models.ForeignKey(to="Release",to_field="ArticleId",verbose_name="文章ID(外键)",on_delete=models.CASCADE)
    Tag=models.CharField(max_length=30,verbose_name="标签",default="无标签")

class Like(models.Model): #^点赞
    ArticleId=models.ForeignKey(to="Release",to_field="ArticleId",verbose_name="文章ID(外键)",on_delete=models.CASCADE)
    UserId=models.ForeignKey(to="Information",to_field="UserId",verbose_name="用户ID(外键)",on_delete=models.CASCADE)
    class Meta:
        unique_together=[("ArticleId","UserId"),]#^限制重复

class Files(models.Model):#^文件
    FilePath=models.TextField(verbose_name="图片路径")
    FileType=models.CharField(max_length=30,verbose_name="标签",null=True)
    UserId=models.ForeignKey(to="Information",to_field="UserId",verbose_name="用户ID(外键)",on_delete=models.CASCADE)
